package _interview75;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 1268. 搜索推荐系统
 */
public class No1268 {
    public List<List<String>> suggestedProducts(String[] products, String searchWord) {
        ArrayList<List<String>> ans = new ArrayList<>();
        Arrays.sort(products);

        int n = searchWord.length();
        for (int i = 1; i <= n; i++) {
            String s = searchWord.substring(0, i);
            ArrayList<String> path = new ArrayList<>();
            for (String product : products) {
                if (path.size() == 3) break;
                else if (product.startsWith(s)) path.add(product);
            }
            ans.add(path);
        }

        return ans;
    }
}
